import { Controller, Get, Query, UseGuards } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth, ApiQuery } from '@nestjs/swagger';
import { MonitorService } from './monitor.service';
import { JwtAuthGuard } from '@/common/guards/jwt-auth.guard';
import { PermissionGuard } from '@/common/guards/permission.guard';
import { RequirePermissions } from '@/common/decorators/permission.decorator';

@ApiTags('系统监控')
@Controller('monitor')
@UseGuards(JwtAuthGuard, PermissionGuard)
@ApiBearerAuth()
export class MonitorController {
  constructor(private readonly monitorService: MonitorService) {}

  @Get('system')
  @RequirePermissions('monitor:system')
  @ApiOperation({ summary: '获取系统监控指标' })
  async getSystemMetrics() {
    return this.monitorService.getSystemMetrics();
  }

  @Get('history')
  @RequirePermissions('monitor:history')
  @ApiOperation({ summary: '获取历史监控数据' })
  @ApiQuery({ name: 'duration', required: false, description: '时间范围：5m, 15m, 1h, 6h, 24h' })
  async getMetricsHistory(@Query('duration') duration?: string) {
    return this.monitorService.getMetricsHistory(duration);
  }

  @Get('system-info')
  @RequirePermissions('monitor:system-info')
  @ApiOperation({ summary: '获取系统信息' })
  async getSystemInfo() {
    return this.monitorService.getSystemInfo();
  }

  @Get('application')
  @RequirePermissions('monitor:application')
  @ApiOperation({ summary: '获取应用程序指标' })
  async getApplicationMetrics() {
    return this.monitorService.getApplicationMetrics();
  }

  @Get('health')
  @RequirePermissions('monitor:health')
  @ApiOperation({ summary: '获取系统健康检查' })
  async getHealthCheck() {
    return this.monitorService.getHealthCheck();
  }

  @Get('logs')
  @RequirePermissions('monitor:logs')
  @ApiOperation({ summary: '获取日志分析' })
  async getLogAnalysis() {
    return this.monitorService.getLogAnalysis();
  }
}